/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Permissive License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Permissive License, please send an email to 
 * ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Permissive License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 *
 * ***************************************************************************/

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;

using System.Diagnostics;
using System.Reflection;
using System.Text;
using Microsoft.Scripting;
using System.Threading;

using Microsoft.Scripting.Internal;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting.Shell;





namespace Nua.Runtime {

    public class SystemState
    {
        private Dictionary<string, Type> _builtinsDict = new Dictionary<string, Type>();
        private Dictionary<Type, string> _builtinModuleNames = new Dictionary<Type, string>();

        public ScriptEngine Engine { get { return _engine; } }
        ScriptEngine _engine;
        // TODO: internal, w/o importer arg
        public SystemState(ScriptEngine engine)
        {
            _engine = engine;
            InitializeBuiltins();
        }

        private void InitializeBuiltins() 
        {
            // hack - because TopPackage is internal
            NuaOps ops = new NuaOps();

            // add Microsoft.Scripting. TODO: when ReflectedPackage moves to M.S.dll this won't be necessary
            //ClrModule.AddReference(typeof(NuaOps).Assembly);

            //Ops.TopPackage.AssemblyLoaded += new EventHandler<AssemblyLoadedEventArgs>(TopPackage_AssemblyLoaded);

            // TODO:// Lua libraries get added here
            //ClrModule.AddReference(ScriptDomainManager.CurrentManager.PAL.LoadAssembly("IronPython.Modules"));
           
        }

        //private void TopPackage_AssemblyLoaded(object sender, AssemblyLoadedEventArgs e) {
        //    foreach (PythonModuleAttribute pma in e.Assembly.GetCustomAttributes(typeof(PythonModuleAttribute), false)) {
        //        Builtins.Add(pma.Name, pma.Type);
        //        BuiltinModuleNames[pma.Type] = pma.Name;
        //    }

        //    builtin_module_names = Tuple.Make(_builtinsDict.Keys);
        //}

        public ClrModule ClrModule {
            get {
                return ClrModule.GetInstance();
            }
        }

        public Dictionary<string, Type> Builtins {
            get {
                return _builtinsDict;
            }
        }

        public Dictionary<Type, string> BuiltinModuleNames {
            get {
                return _builtinModuleNames;
            }
        }
        
    }
}
